package com.caipiao.crawler.run;

import com.caipiao.constant.CrawlerConstants;
import com.caipiao.crawler.daletou.DaletouResultPage;
import com.caipiao.crawler.daletou.DaletouResultPipeline;
import com.caipiao.crawler.mapper.LotteryNumberMapper;
import com.caipiao.crawler.qixingcai.QixingcaiResultPage;
import com.caipiao.crawler.qixingcai.QixingcaiResultPipeline;
import com.caipiao.crawler.shengfucang.ShengfucangDetailPage;
import com.caipiao.crawler.shengfucang.ShengfucangDetailPipeline;
import com.caipiao.crawler.shengfucang.ShengfucangResultPage;
import com.caipiao.crawler.shengfucang.ShengfucangResultPipeline;
import com.caipiao.util.DBTools;
import org.apache.ibatis.session.SqlSession;
import us.codecraft.webmagic.Spider;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by adminitrator on 2018/7/28.
 */
public class Shengfucang implements RunCrawler {

    @Override
    public void run() {
        Spider.create(new ShengfucangResultPage())
                .addUrl(CrawlerConstants.SHENGFUCANG_HISTORY_URL)
                .addPipeline(new ShengfucangResultPipeline())
                .thread(4)
                .run();
    }

    @Override
    public void runHistory() {
        List<String> urls = new ArrayList<String>();
        for (int i = 18058; i < 18087; i++) {
            urls.add(CrawlerConstants.SHENGFUCANG_DATA_URL + i);
        }
        Spider.create(new ShengfucangResultPage())
                .addUrl(urls.toArray(new String[0]))
                .addPipeline(new ShengfucangResultPipeline())
                .thread(4)
                .run();
    }

    public void runNowMatch(){
        //获取当前比赛期数
        String url = CrawlerConstants.SHENGFUCANG_NOW_MATCHLIST_URL;
        Spider.create(new ShengfucangResultPage())
                .addUrl(url)
                .addPipeline(new ShengfucangResultPipeline())
                .thread(4)
                .run();

    }
    /**
     * 更新胜负场销售量和奖池信息
     */
    public void runSaleDetail(){
        String url = CrawlerConstants.SHENGFUCANG_HISTORY_URL;
        Spider.create(new ShengfucangDetailPage())
                .addUrl(url)
                .addPipeline(new ShengfucangDetailPipeline())
                .thread(4)
                .run();
    }
}
